#ifndef _IDATAGRAM_FACTORY_20120414
#define _IDATAGRAM_FACTORY_20120414

#include "listbuffer.hpp"
#include "idatagram.hpp"
#include "streamer.hpp"
#include "buffer.hpp"
#include "base.hpp"

using namespace buffer;

namespace datagram
{
	class IDatagramFactory
	{
		public :
			virtual ~IDatagramFactory() {}

			int  decode(ListBuffer & listbuffer, IDatagram *& datagram);
			void encode(ListBuffer & listbuffer, IDatagram * datagram);

			bool frame(ListBuffer & listbuffer);
		public :
			virtual int decode(uint32_t type, Streamer & streamer, IDatagram *& datagram) = 0;
			virtual void encode(uint32_t type, Streamer & streamer, IDatagram * datagram) = 0;

		public :
			static uint32_t get_magic(ListBuffer & listbuffer);
			static uint32_t get_length(ListBuffer & listbuffer);
			static uint32_t get_type(ListBuffer & listbuffer);

		public :
			const static uint32_t MAX_DATAGRAM_SIZE = 1024 * 1024;
	};
};

#endif

